import { USER_INFO_KEY } from "@/libs/KEY";

export interface LanguageEnum {
  label: string
  value: string
}
export const useLanguageEnum = ():LanguageEnum[] => {
  return [
    {
      label: "中文繁體",
      value: "ZH-HANT"
    },
    {
      label: "中文简体",
      value: "ZH-CN"
    },
    {
      label: "English",
      value: "EN"
    }
  ]
}
function isSimplifiedChinese() {
  const language = navigator.language;
  return language === 'zh-CN';
}
function isTraditionalChinese() {
  const language = navigator.language;
  return language === 'zh-TW' || language === 'zh-HK';
}
function isEnglish() {
  const language = navigator.language;
  return language.startsWith('en');
}

export const useDefaultLanguage = ()=> {
  return isSimplifiedChinese()? "ZH-CN" : isTraditionalChinese()? "ZH-HANT" : isEnglish()? "EN" : "ZH-HANT";
}

export const getCurrentLanguage = ()=> {
  const userInfo = window.localStorage.getItem(USER_INFO_KEY);
  if(userInfo){
    return JSON.parse(userInfo)?.setting?.languageCode || useDefaultLanguage();
  }
  return  useDefaultLanguage()
}